#ifndef BASEWINDOWMANAGER_H
#define BASEWINDOWMANAGER_H

#include <windows.h>
#include "baseManager.h"


class uiMenu
{
public:
	static unsigned int Get()
	{
		static unsigned int uiMenu = 0;
		return ++ uiMenu;
	}
};

template <class T>
class baseWindowManager :
	public baseManager<T >
{
public:
	baseWindowManager();
	int setInstance(HINSTANCE hInstance);
	HINSTANCE getInstance();
	unsigned int increaseMenu();
	T* getObjByMenu(unsigned int uiMenu);
	T* getObjByHwnd(HWND hwnd);
	int OnPaint();
	virtual int CreateSubWindows(HWND hwnd) = 0;
protected:
	HINSTANCE m_hInstance;
};

template <class T>
baseWindowManager<T>::baseWindowManager()
{
	m_hInstance = NULL;
}

template <class T>
int
baseWindowManager<T>::setInstance(HINSTANCE hInstance)
{
	m_hInstance = hInstance;
	return 0;
}

template <class T>
HINSTANCE
baseWindowManager<T>::getInstance()
{
	return m_hInstance;
}

template <class T>
unsigned int
baseWindowManager<T>::increaseMenu()
{
	return uiMenu::Get();
}

template <class T>
T*
baseWindowManager<T>::getObjByMenu(unsigned int uiMenu)
{
	for (THISLIST::iterator iter = m_list.begin(); iter != m_list.end(); ++ iter){
		if (NULL != (*iter)){
			if (uiMenu == (*iter)->getMenu()){
				return (*iter);
			}		
		}
	}
	return NULL;
}

template <class T>
T*
baseWindowManager<T>::getObjByHwnd(HWND hwnd)
{
	for (THISLIST::iterator iter = m_list.begin(); iter != m_list.end(); ++ iter){
		if (NULL != (*iter)){
			if (hwnd == (*iter)->getHwnd()){
				return (*iter);
			}		
		}
	}
	return NULL;
}

template<class T>
int
baseWindowManager<T>::OnPaint()
{
	for (THISLIST::iterator iter = m_list.begin(); iter != m_list.end(); ++ iter){
		if (NULL != (*iter)){
			(*iter)->OnPaint();
		}
	}
	return 0;
}

#define CREATESUBWINDOW(manager, name, hwnd, classname) \
pSubWin = new classname; \
pSubWin->Create(name, hwnd); \
manager::Get()->push(pSubWin);

#endif